package com.doitedu.mr.day04.bean;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @Date 2021/12/3
 * @Created by HANGGE
 * @Description
 * 1) 封装json数据
 * 2) 放在了Mapper的value的位置  这个类需要序列化  使用HDP的序列化方式
 */
public class MovieWriable  implements Writable {

    private  String  movie ;
    private  double  rate ;
    private  String timeStamp ;
    private  String uid ;

    /**
     * 注意保留空参构造器
     * @return
     */
    public String getMovie() {
        return movie;
    }

    public void setMovie(String movie) {
        this.movie = movie;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    @Override
    public String toString() {
        return "Movie{" +
                "movie='" + movie + '\'' +
                ", rate=" + rate +
                ", timeStamp='" + timeStamp + '\'' +
                ", uid='" + uid + '\'' +
                '}';
    }
// 序列化
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(movie);
        dataOutput.writeDouble(rate);
        dataOutput.writeUTF(timeStamp);
        dataOutput.writeUTF(uid);

    }
// 反序列化
    public void readFields(DataInput dataInput) throws IOException {
        // 和写出的数据类型和顺序保证一致
        movie = dataInput.readUTF();
        rate =dataInput.readDouble();
        timeStamp = dataInput.readUTF();
        uid = dataInput.readUTF() ;

    }
}
